package com.itheima.controller;

import com.itheima.pojo.NursingProject;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.ProjectParam;
import com.itheima.pojo.Result;
import com.itheima.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursingProject")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    public Result getAll(ProjectParam projectParam) {
        PageResult pageResult = nursingProjectService.getAll(projectParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result addProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.addProject(nursingProject);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getProject(@PathVariable Long id){

        NursingProject project = nursingProjectService.getProjectById(id);
        return Result.success(project);
    }
    @PutMapping
    public Result updateProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateProject(nursingProject);
        return Result.success();
    }
    @DeleteMapping
    public Result deleteProject(@RequestParam Long id){
        nursingProjectService.deleteProject(id);
        return Result.success();
    }


}
